from twisted.internet import reactor, endpoints
from twisted.web import server, resource


class WebServerDemo(resource.Resource):
    isLeaf = True
    numberRequests = 0

    def render_GET(self, request):
        self.numberRequests += 1
        request.setHeader(b"content-type", b"text/plain")
        content = u"I am request #{}\n".format(self.numberRequests)
        return content.encode("ascii")


def _test_web():
    """
    _test_web()
    >
    192.168.1.103:8000
    """
    endpoints.serverFromString(reactor, "tcp:8000:interface=0.0.0.0").listen(server.Site(WebServerDemo()))
    reactor.run()


if __name__ == '__main__':
    _test_web()
